package com.yhyvr.console.controller.common;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lz.mybatis.jdbc.auto.dao.CommonRegionMapper;
import com.lz.mybatis.jdbc.auto.model.CommonRegion;
import com.lz.mybatis.jdbc.auto.model.CommonRegionExample;
import com.yhyvr.pojo.resp.CommonResp;
import com.yhyvr.pojo.resp.HttpResult;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by tech6 on 2016/8/25.
 */

@Controller
public class CommonRegionController {

    @Resource
    private CommonRegionMapper commonRegionMapper;

    /**
     * 通用地址查询
     * @param id
     * @return
     */
    @RequestMapping("/console/common/getNext/{id}")
    public @ResponseBody HttpResult getNext(@PathVariable int id){
        CommonRegionExample commonRegionExample = new CommonRegionExample();
        commonRegionExample.createCriteria().andPidEqualTo(id);
        List<CommonRegion> commonRegions =  commonRegionMapper.selectByExample(commonRegionExample);
        Map<String,String> map = Maps.newHashMap();
        for (CommonRegion commonRegion : commonRegions) {
            map.put(commonRegion.getId().toString(),commonRegion.getName());
        }
        return CommonResp.getSuccessByData(map);
    }
}
